Skip to content

feat(sandbox): add encode_base64 opt-in to read_file tool with backward-compatible default#79

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/add-read-file-tool
Draft

feat(sandbox): add encode_base64 opt-in to read_file tool with backward-compatible default#79
Copilot wants to merge 3 commits intomainfrom
copilot/add-read-file-tool

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 8, 2026

read_file in CodeInterpreterToolSet lacked a way to safely handle binary files, as it only returned raw text with no encoding control.

Changes

  • CodeInterpreterToolSet.read_file: default behavior returns plain text unchanged (backward compatible); response now includes an encoding field ("raw" or "base64")
  • Added encode_base64: bool = False parameter — set True to receive base64-encoded content, useful for binary files
  • Handles both str and bytes from the underlying API when encoding

Example

# Default — plain text, backward compatible
result = toolset.read_file(path="/tmp/notes.txt")
# {"path": "/tmp/notes.txt", "content": "hello world", "encoding": "raw"}

# Opt-in base64 for binary files
result = toolset.read_file(path="/tmp/output.bin", encode_base64=True)
# {"path": "/tmp/output.bin", "content": "aGVsbG8=", "encoding": "base64"}

import base64
content = base64.b64decode(result["content"])

Copilot AI and others added 2 commits April 8, 2026 06:27
- Modified read_file in CodeInterpreterToolSet to encode file content
  as base64 by default; response includes 'encoding' field ('base64' or 'raw')
- Added optional 'raw' parameter (default False): when True, returns
  plain text content unchanged
- Handles both str and bytes content from the underlying API
- Added unit tests covering base64 default, roundtrip, bytes input,
  raw=True, and raw=False equivalence to default
- mypy type check passed (324 files, no issues)

Agent-Logs-Url: https://github.com/Serverless-Devs/agentrun-sdk-python/sessions/410c37c7-b485-46a3-806d-026c8d397150

Co-authored-by: OhYee <13498329+OhYee@users.noreply.github.com>
@OhYee
Copy link
Copy Markdown
Member

OhYee commented Apr 8, 2026

@copilot 如果要保持向前兼容,是否应该默认原文,传入 base64 后使用 base64?

…se64 opt-in

- Default behavior now returns plain text (backward compatible with
  callers that expected raw content from the original read_file)
- New encode_base64=True parameter opts into base64 encoding for
  binary file support
- Response always includes 'encoding' field ('raw' or 'base64')
- Updated unit tests to reflect new API

Agent-Logs-Url: https://github.com/Serverless-Devs/agentrun-sdk-python/sessions/c48cff08-0e34-425e-a6e6-aafbaee14a00

Co-authored-by: OhYee <13498329+OhYee@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 8, 2026

@copilot 如果要保持向前兼容,是否应该默认原文,传入 base64 后使用 base64?

已按此思路调整(commit ed0b462):

  • 默认行为改回返回原始文本(encoding: "raw"),保持向前兼容
  • 新增 encode_base64: bool = False 参数,传入 True 时返回 base64 编码内容(encoding: "base64"
# 默认:原文(向前兼容)
result = toolset.read_file(path="/tmp/notes.txt")
# {"path": "...", "content": "hello world", "encoding": "raw"}

# 按需开启 base64(适合二进制文件)
result = toolset.read_file(path="/tmp/output.bin", encode_base64=True)
# {"path": "...", "content": "aGVsbG8=", "encoding": "base64"}

Copilot AI changed the title feat(sandbox): add base64 encoding to read_file tool with raw passthrough option feat(sandbox): add encode_base64 opt-in to read_file tool with backward-compatible default Apr 8, 2026
Copilot finished work on behalf of OhYee April 8, 2026 07:04
Copilot AI requested a review from OhYee April 8, 2026 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants